package test.com.sms.selenium.sc.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class ScHomePageUtil extends SeleniumPageUtil 
{
	public final static By WELCOME_LABEL = By.xpath("//span[@class='username']");
	public final static By HOME_LINK_DISPATCH_PORTAL = By.xpath("//a[contains(text(), 'Dispatch Portal')]");
	public final static By HOME_LINK_UAT = By.xpath("//a[contains(text(), 'UAT')]");
	public static final By HOME_LINK_HOME = By.xpath("//a[contains(text(), 'Home')]");
	public static final By HOME_LINK_SEARCH = By.xpath("//a[contains(text(), 'Search')]");
	public static final By HOME_LINK_TICKET = By.xpath("//a[contains(text(), 'Tickets')]");
	public final static By HOME_LINK_REPORTS = By.xpath("//a[contains(text(), 'Reports')]");
	public final static By HOME_LINK_MAPS = By.xpath("//a[contains(text(), 'Maps')]");
	public final static By HOME_LINK_TRACKING = By.xpath("//a[contains(text(), 'Tracking')]");
	public final static By HOME_FONT_TEST_STE = By.xpath("html/body/center[1]/h4/font");
	
	/** if element HOME_SPAN_EXPIRATION shows, this page should has already been loaded.*/
	public final static void waitForPageToLoad() {
		SeleniumUtil.waitOnElements(new By[]{HOME_LINK_HOME, HOME_LINK_SEARCH, HOME_LINK_TICKET});
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(HOME_LINK_HOME));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(HOME_LINK_TICKET));
		SeleniumUtil.waitForFixedMilliseconds(1000);
	}
	
	/**
	 * Enter index page, index page generally speaking same as dispatch page
	 * */
	public final static void enterIndexPage() {
		SeleniumUtil.get(ScLoginPageUtil.SC_ROOT_URL + ScLoginPageUtil.INDEX_PAGE_URL);
	}
	
	/**
	 * Enter dispatch page.
	 * */
	public final static void enterDispatchPage() {
//		String title = SeleniumUtil.getCachedElement(ScHomePageUtil.HOME_FONT_TEST_STE).getText().trim();
		 SeleniumUtil.click(SeleniumUtil.findElement(HOME_LINK_DISPATCH_PORTAL));
		
//		if("TEST SITE".equals(title)){
//			SeleniumUtil.click(SeleniumUtil.findElement(HOME_LINK_DISPATCH_PORTAL));
//		}else if("UAT SITE".equals(title)){
//			SeleniumUtil.click(SeleniumUtil.findElement(HOME_LINK_UAT));
//		}
	}
	
	public static void enterSearchPage() {
		SeleniumUtil.click(SeleniumUtil.findElement(HOME_LINK_SEARCH));
		ScSearchPageUtil.waitForPageToLoad();
	}
	
	public static void enterTicketsPage() {
		SeleniumUtil.click(SeleniumUtil.findElement(HOME_LINK_TICKET));
		ScTicketsPageUtil.waitForPageToLoad();
	}
}
